import controller.Sqlsession;
import dao.UserMapper;
import io.Resource;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import pojo.User;
import utils.SqlSessionFactory;
import utils.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

public class test {

    public static void main(String[] args) throws DocumentException {
        InputStream inputStream = Resource.readConfig("sqlConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        Sqlsession sqlsession = sqlSessionFactory.openSession();

//        //使用sqlsession操作
//        List<Object> objects = sqlsession.selectList("userMapper.findAll", null);
//        for (Object object : objects) {
//            System.out.println(object.toString());
//        }

        //使用mapper 操作
        UserMapper mapper = sqlsession.getMapper(UserMapper.class);
        List<User> objects = mapper.selectList();
        for (User object : objects) {
            System.out.println(object.toString());
        }

        System.out.println("------------------------");

        User user = new User();
        user.setName("拉钩教育");
        user.setId(5);
//        Integer integer = mapper.deleteById(user);
        mapper.updateNameById(user);
        System.out.println("修改操作执行完成");

        System.out.println("------------------------");
        objects = mapper.selectList();
        for (User object : objects) {
            System.out.println(object.toString());
        }



    }
}
